package com.portal.framework.util;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;

public class SystemConfig {
	private static SystemConfig indexConfig=null;
	
	private String server;  //服务器路径
	private String webUrl;   //调用系统后台webService的连接路径
	
	private SystemConfig() {
		super();
        Properties pro=getProperties();
		
		String server = pro.getProperty("server");
		this.server = server;
		
		String webUrl=pro.getProperty("sysWebService");
		this.webUrl=webUrl;
		
	}


	synchronized public static SystemConfig getInstance(){
        if(indexConfig==null){
        	indexConfig=new SystemConfig();
         }
         return indexConfig;
    }

	//获取属性文件
	private Properties getProperties(){
		String tomcatPath = SystemConfig.class.getClassLoader().getResource("").toString();
		if(tomcatPath!=null&&tomcatPath.length()>0){
			int s = tomcatPath.lastIndexOf("classes");
			tomcatPath = tomcatPath.substring(0,s );
			int pos=tomcatPath.indexOf("file:");    
		    if(pos>-1) tomcatPath=tomcatPath.substring(pos+5);    
		}
		String sourceFileName=tomcatPath+"config/systemConfig.properties";
		try{    
			sourceFileName=java.net.URLDecoder.decode(sourceFileName,"utf-8");    
		    }catch(Exception e){throw new RuntimeException(e);} 
		FileInputStream in;
		Properties prop = new Properties();
		try {
			in = new FileInputStream(sourceFileName);
			prop.load(in);
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}catch (IOException e) {
			e.printStackTrace();
		}
		return prop;
	}


	public String getServer() {
		return server;
	}


	public void setServer(String server) {
		this.server = server;
	}


	public String getWebUrl() {
		return webUrl;
	}


	public void setWebUrl(String webUrl) {
		this.webUrl = webUrl;
	}
	
}
